package exam.day38;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] arr = new int[n][n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int[] num = new int[3];
        int q = in.nextInt();
        while(q-- != 0) {
            int x = in.nextInt();
            num[x]++;
        }
        if(num[1] % 2 == 0 && num[2] % 2  == 0) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    System.out.print(arr[i][j] + " ");
                }
                System.out.println();
            }
            return;
        }
        if(num[1] % 2  == 1 && num[2] % 2  == 0) {
            for(int i = n - 1; i >= 0; i--) {
                for(int j = n - 1; j >= 0; j--) {
                    System.out.print(arr[i][j] + " ");
                }
                System.out.println();
            }
            return;
        }
        if(num[1] % 2  == 0 && num[2] % 2  == 1) {
            for(int i = n - 1; i >= 0; i--) {
                for(int j = 0; j < n; j++) {
                    System.out.print(arr[i][j] + " ");
                }
                System.out.println();
            }
            return;
        }
        if(num[1] % 2  == 1 && num[2] % 2  == 1) {
            for(int i = 0; i < n; i++) {
                for(int j = n - 1; j >= 0; j--) {
                    System.out.print(arr[i][j] + " ");
                }
                System.out.println();
            }
            return;
        }
    }
}
